<template>
  <el-menu default-active="1-4-1" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" @open="handleOpen" @close="handleClose" :collapse="isCollapse">
   <h4>{{isCollapse?'商家':'商家个人中心'}}</h4>
   <el-menu-item @click="linkMenu(item)" v-for="item,index in noChildren" :index="index.toString()" :key="item.path">
    <i :class="'el-icon-' +item.icon "></i>
    <span slot="title">{{item.label}}</span>
  </el-menu-item>
  <el-submenu v-for="item,index in Children" :index="index.toString()" :key="item.path">
    <template slot="title">
      <i :class="'el-icon-' +item.icon"></i>
      <span slot="title">{{item.label}}</span>
    </template>
    <el-menu-item-group   v-for="(subItem) in item.children" :key="subItem.path"> 
      <el-menu-item @click="linkMenu(subItem)" :index="subItem.path.toString()">{{subItem.label}}</el-menu-item>
    </el-menu-item-group>
  </el-submenu>
</el-menu>
</template>

<style lang="less" scoped>

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-menu{
      height: 100%;
      border: none;
      h4{
        //   margin-top: 10px;
        line-height: 50px;
          color: #fff;
          text-align: center;
      }
  }
</style>

<script>
  export default {
    data() {
      return {
        // isCollapse:false,
        menu:[
            {
                path:'/shoppersonal',
                name:'myshop',
                label:'我的店铺',
                icon:'s-shop',
            },
            {
                label:'店铺信息',
                icon:'shopinformation',
                children:[
                     {
                        path:'/shoppersonal/information',
                        name:'Shopinformation',
                        label:'修改店铺基本信息',
                        icon:'setting',
                    },
                     {
                        path:'/shoppersonal/picture',
                        name:'ShopPicture',
                        label:'修改店铺封面',
                        icon:'setting',
                    }
                ]
            },
            {
                path:'/shoppersonal/coupon',
                name:'coupon',
                label:'优惠券管理',
                icon:'s-management',
            },
             {
                path:'/shoppersonal/dynamic',
                name:'dynamic',
                label:'发布动态',
                icon:'s-promotion',
            },
             {
                path:'/shoppersonal/shoporder',
                name:'shoporder',
                label:'店铺订单',
                icon:'user',
            },
        ]
      };
    },
    computed:{
        noChildren(){
            return this.menu.filter(item=>!item.children )
        },
         Children(){
            return this.menu.filter(item=>item.children )
        },
        isCollapse(){
          return this.$store.state.tab.isCollapse
        }
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        linkMenu(item){
          this.$router.push(item.path)
          this.$store.commit('selectMenu',item)
        }
    }
  }
</script>